package com.ergwang.listener; /**
 * @author：ergwang
 * @Date: 2020/5/30
 * @Time: 17:56
 */

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import javax.servlet.http.HttpSessionBindingEvent;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

@WebListener()
public class ApplicationListener implements ServletContextListener{

    public ApplicationListener() {

    }

    public void contextInitialized(ServletContextEvent sce) {
        InputStream resourceAsStream = ApplicationListener.class.getClassLoader().getResourceAsStream("application.properties");
        Properties properties = new Properties();
        try {
            properties.load(resourceAsStream);
            String domain = properties.getProperty("domain");
            sce.getServletContext().setAttribute("domain", domain);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void contextDestroyed(ServletContextEvent sce) {

    }
}
